<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>心理健康状况</h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>心理健康状况</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">

                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column prop="id" label="ID" align="center"></el-table-column>
                        <el-table-column prop="body" label="躯体化" align="center"></el-table-column>
                        <el-table-column prop="assessment_date" label="体检日期" align="center"></el-table-column>
                        <el-table-column prop="Obsession" label="强迫症" align="center"></el-table-column>
                        <el-table-column prop="anxious" label="焦虑" align="center"></el-table-column>
                        <el-table-column prop="Paranoia" label="偏执" align="center"></el-table-column>
                        <el-table-column prop="member_id" label="会员id" align="center"></el-table-column>
                        <el-table-column prop="name" label="会员名称" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="编辑" :visible.sync="dialogFormVisible">
                            <el-form label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="18">
                                        <el-form-item label="躯体化">
                                            <el-input v-model="formData.body"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="18">
                                        <el-form-item label="体检日期">
                                            <el-input v-model="formData.assessment_date"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="18">
                                        <el-form-item label="强迫症">
                                            <el-input v-model="formData.Obsession"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="18">
                                        <el-form-item label="焦虑">
                                            <el-input v-model="formData.anxious"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="18">
                                        <el-form-item label="偏执">
                                            <el-input v-model="formData.Paranoia"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                pagination: {//分页相关模型数据
                    currentPage: 1,//当前页码
                    pageSize:9,//每页显示的记录数
                    total:0,//总记录数
                    queryString:null//查询条件

                },
                dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//编辑表单是否可见
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                //调用分页查询方法完成分页查询
                this.findPage();
            },
            methods: {
                //点击编辑的  确定  按钮操作
                handleEdit() {
                    //发送ajax请求，将表单数据提交到Controller
                            axios.post("/psychologyManager/edit.do",this.formData).then((res) => {
                                if(res.data.flag){
                                    //处理成功
                                    this.$message({
                                        type:'success',
                                        message:res.data.message
                                    });
                                    //关闭编辑窗口
                                    this.dialogFormVisible = false;
                                    //分页查询
                                    this.findPage();
                                }else{
                                    //处理失败
                                    this.$message.error(res.data.message);
                                }
                            });
                },

                //分页查询
                findPage() {
                    var param = {
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                    };

                    //发送ajax请求，进行分页查询
                    axios.post("/psychology/findAllPsychologyr.do",param).then((res) => {
                        this.pagination.total = res.data.total;
                        this.dataList = res.data.rows;
                    });

                },


                // 点击编辑,弹出编辑窗口
                handleUpdate(row) {
                    this.dialogFormVisible = true;
                    //回显数据
                    axios.post("/psychologyManager/findById.do?id=" + row.id).then((res) => {
                        if(res.data.flag){
                            this.formData = res.data.data;//为模型数据赋值，基于VUE数据绑定进行回显
                        }else{
                            this.$message.error(res.data.message);
                        }
                    });
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;//指定最新的页码
                    this.findPage();
                },

                showMessage(r){
                    if(r == 'Error: Request failed with status code 403'){
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    }else{
                        this.$message.error('未知错误');
                        return;
                    }
                },

                // 删除
                handleDelete(row) {
                    //弹出确认框
                    this.$confirm('你确定要删除当前数据吗？','提示',{
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //发送ajax请求，将id提交到Controller
                        axios.post("/psychologyManager/delete.do?id=" + row.id).then((res) => {
                            if(res.data.flag){
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                this.findPage();
                            }else{
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).catch((r) => {
                            this.showMessage(r);
                        });
                    }).catch(() => {
                        this.$message("已取消");
                    });
                }
            }
        })
    </script>
</html>
